

package com.zy.controller;

import com.zy.entity.Staff;
import com.zy.service.StaffService;
import com.zy.util.R;
import javax.annotation.Resource;

import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping({"staff"})
public class StaffController {
    @Resource
    StaffService staffService;


    @GetMapping({"getById/{id}"})
    public R getById(@PathVariable Integer id) {
        return R.ok().put("staff", this.staffService.getById(id));
    }

    @PutMapping({"save"})
    public R save(@RequestBody Staff staff) {
        this.staffService.save(staff);
        return R.ok();
    }

    @PostMapping({"updateById"})
    public R updateById(@RequestBody Staff staff) {
        this.staffService.updateById(staff);
        return R.ok();
    }
    @PostMapping({"status/{id}"})
    public R status(@PathVariable Integer id) {
        this.staffService.status(id);
        return R.ok();
    }

    @DeleteMapping({"delete/{id}"})
    public R delete(@PathVariable Integer id) {
        this.staffService.delete(id);
        return R.ok();
    }

    @PostMapping({"page/{page}/{limit}"})
    public R tree(@RequestBody Staff staff, @PathVariable Integer page, @PathVariable Integer limit) {
        return R.ok().put("pageInfo", this.staffService.page(staff, page, limit));
    }

    @PostMapping({"login"})
    public R login(@RequestBody Staff staff) {
        return this.staffService.login(staff) == 1 ? R.ok() : R.error();
    }

    @GetMapping("logout")
    public R logout() {
        return this.staffService.logout() == 1 ? R.ok() : R.error();
    }
}
